package br.com.ews.agenda.model;

import java.util.List;

import android.content.Context;
import android.util.Log;
import br.com.ews.agenda.model.helpers.GenericDao;

public class AgendaDao extends GenericDao<Agenda> {

    public AgendaDao(Context context) {
        super(context, Agenda.class);
    }

    /**
     * @return String de backup com os inserts da tabela agenda.
     */
    public String backup() {
        String insert = "INSERT INTO agenda ("
                + Agenda._ID
                + ","
                + Agenda._DESCRICAO
                + ","
                + Agenda._DATA
                + ","
                + Agenda._NOTIFICAR
                + ","
                + Agenda._DIA_HORA
                + ","
                + Agenda._NOTIFICADA
                + ") VALUES";

        List<Agenda> agendas = getAll();
        StringBuffer values = new StringBuffer();
        for (Agenda agenda : agendas) {
            values.append(" (").append(agenda.getId()).append(", '").append(agenda.getDescricao()).append("', '").append(agenda.getData())
                    .append("', ").append(agenda.getNotificar()).append(", '").append(agenda.getDiaHora()).append("', ")
                    .append(agenda.getNotificada()).append("),");
        }

        String inserts = insert + values.toString();
        Log.d("Agenda Backup", inserts);

        return inserts;
    }
}